package 笔试.字节;

import java.util.*;

/**
 * @author:谢君臣
 * @Date:2021/9/26-21:01
 * @version:1.0
 * @function:
 */
public class Main0926 {

//5
//1 2 1 2 1
//2

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        int t = 0;
        while (t < n) {
            arr[t++] = scanner.nextInt();
        }
        int k = scanner.nextInt();
        int i = 0, j = arr.length - 1;
        while (arr[i] != k) i++;
        while (arr[j] != k) j--;
        int index = find(arr, k, i, j);
        function(arr, k, i, j, 0, index);
    }

    public static void function(int[] arr, int k, int l, int r, int count, int index) {
        if (index - l == 0) {
            int temp = index;
            while (arr[temp] == k) temp++;
            arr[r] = arr[temp];
            arr[temp] = k;
        } else {
            arr[l] = arr[index - 1];
            arr[index - 1] = k;
            index--;
        }
        count++;
        while (arr[l] != k) l++;
        while (r >= 0 && arr[r] != k) r--;
        int temp1 = l;
        boolean flag = true;
        while (temp1 <= r) {
            if (arr[temp1++] != k) {
                flag = false;
                break;
            }
        }
        if (flag) {
            System.out.println(count);
        } else
            function(arr, k, l, r, count, index);
    }

    // 找到最长的位置起始位置
    public static int find(int[] arr, int k, int l, int r) {
        int max = 0, index = 0, count = 0;
        for (; l <= r; l++) {
            if (arr[l] == k) {
                count++;
            } else {
                count = 0;
            }
            if (count >= max) {
                max = count;
                index = l - max + 1;
            }
        }
        return index;
    }
}